class_name  子弹2
extends CharacterBody2D
@onready var 信号管理器=信号管理.new()
var speed=600
var direction:Vector2
@onready var 子弹超时销毁=$Timer/Timer
#
func _ready() -> void:
	信号管理器.清除全部子弹.connect(_on_timer_timeout超时)


func _physics_process(_delta: float) -> void:

	# 检查是否有碰撞发生
	if get_slide_collision_count() > 0:
		# 获取最后一次碰撞的信息
		var collision_info = get_last_slide_collision()
		var normal = collision_info.get_normal()
		direction = direction.bounce(normal)
		velocity = direction * speed
	move_and_slide()


func _on_hit_box_hit(equl_name) -> void:
	if equl_name=="player_hurtBox" or equl_name=="bullet_hitBox":
		return
	
	#queue_free()
func 获取发射方向(_direction:Vector2):
	self.direction=_direction


func _on_timer_timeout() -> void:
	if multiplayer.is_server():
		销毁子弹local.rpc()
@rpc("any_peer","call_local","reliable")	
func 销毁子弹local():
	queue_free()


func _on_bullet_hit_box_body_entered(body: Node2D) -> void:
	if body.is_in_group("墙"):
		print(body)

func _on_timer_timeout超时() -> void:
	#if not multiplayer.is_server():
	if multiplayer.is_server():
		queue_free()
